package com.lijy.list;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

public class LinkedListTest {

    public static void main(String[] args) {
        List<String> a = new LinkedList<String>();
        a.add("Amy");
        a.add("Bob");
        a.add("Linda");

        List<String> b = new LinkedList<String>();
        b.add("Dog");
        b.add("Cat");
        b.add("Pig");
        b.add("Duck");

        ListIterator<String> aIter = a.listIterator();
        Iterator<String> bIter = b.iterator();

        while (bIter.hasNext()) {
            if (aIter.hasNext()) {
                String element = aIter.next();
                System.out.println(element);
            }
            aIter.add(bIter.next());
        }

        System.out.println(a);//[Amy, Dog, Bob, Cat, Linda, Pig, Duck]

        System.out.println(b);//[Dog, Cat, Pig, Duck]
        bIter = b.iterator();
        while (bIter.hasNext()) {
            bIter.next();
            bIter.remove();
        }
        System.out.println(b);//[]

        a.removeAll(b);
        System.out.println(a);


    }
}
